package com.shop.service.impl;

import com.github.pagehelper.PageInfo;
import com.shop.entity.UserCoupon;
import com.shop.mapper.UserCouponMapper;
import com.shop.service.UserCouponService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author XCH
 * @date 2025 - 05 - 19
 */
@Service("userCouponService")
@RequiredArgsConstructor
@Transactional(rollbackFor = RuntimeException.class,
        propagation = Propagation.REQUIRED)
public class UserCouponServiceImpl implements UserCouponService {

    private final UserCouponMapper userCouponMapper;
    @Override
    public PageInfo<UserCoupon> listUserCoupon(Integer userId, Integer pageNum, Integer pageSize) {
        return new PageInfo<>(userCouponMapper.listUserCoupon(userId,pageNum, pageSize));
    }
    @Override
    public UserCoupon getUserCouponById(Integer id) {
        return userCouponMapper.getUserCouponById(id);
    }
    @Override
    public void addUserCoupon(Integer userId, Integer couponId, Integer used) {
        if (userId == null || couponId == null || used == null) {
            throw new RuntimeException("参数错误");
        }
        userCouponMapper.addUserCoupon(userId, couponId, used);
    }
    @Override
    public void updateUserCoupon(UserCoupon userCoupon) {
        userCouponMapper.updateUserCoupon(userCoupon);
    }
    @Override
    public void deleteUserCoupon(Integer id) {
        userCouponMapper.deleteUserCoupon(id);
    }

    @Override
    public int getTotal(Integer userId) {
        return userCouponMapper.getTotal(userId);
    }
}
